home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / ja90 / TAS.txt < prev   
Encoding:
Text File  |  1991-01-22  |  19.1 KB  |  377 lines

  1.  
  2. Amiga TAS Cycles
  3.  
  4. A Study of the Viability of the TAS Instruction on the Zorro II
  5. Bus
  6.  
  7. by Dave Haynie
  8.  
  9. There has been a considerable amount of confusion about the use of the
  10. TAS, or Test And Set, instruction on Amiga systems for quite some
  11. time.  Historically, the 68000 implementation of the bus lock required
  12. by TAS has been a headache for many 68000 system designers, and Amiga
  13. engineers haven't been excluded from this.  While the problem of TAS
  14. alone is an important issue, the evolution of official TAS support on
  15. Amiga systems further complicates the matter.  This article won't give
  16. a clear answer to the "can I use TAS" question, since that answer
  17. changes based on the context of TAS's use.  What I'm trying to do here
  18. is explain why TAS is a problem, what various Amiga systems do with
  19. TAS, and when TAS might be safely used by a Zorro II expansion
  20. board.
  21.  
  22. The Need For TAS?
  23.  
  24. The TAS instruction is designed to support hardware locked semaphores
  25. between multiple processors in a system.  The idea is that making a
  26. read cycle, ALU operation, and write cycle an atomic operation will
  27. allow the 68000 to check on the value of a semaphore in memory and set
  28. this semaphore if currently unset, all without the possibility of
  29. another processor gaining access to the memory in between the read and
  30. write phases.  Presumably, as long as shared structures in a
  31. multiprocessing system are all guarded by semaphores, and all
  32. semaphores are obtained under bus lock protection, then the
  33. possibility of uncontrolled simultaneous access of these shared
  34. resources is eliminated.
  35.  
  36. In the general case, this is called bus locking, and it's a
  37. perfectly valid concept.  The problem stems from the way the 68000
  38. designers chose to lock the bus.  This TAS-generated bus lock becomes
  39. a special case 68000 cycle that's often not correctly supported by
  40. hardware.  For this reason, TAS should never be used on Zorro II
  41. devices that aren't specifically designed to support it.  As long as
  42. you're not dealing with multiprocessor systems, TAS isn't necessary.
  43. The remainder of the document will be concerned with multiprocessing
  44. systems; the cases in which TAS is very useful, if not actually
  45. necessary.
  46.  
  47. It should be noted that the TAS instruction is neither necessary nor
  48. supported on the Amiga's Chip memory bus.  Although the Amiga's
  49. blitter and Copper do serve to provide a form of multiprocessing on
  50. the Chip bus, this is a specialized multiprocessing where the blitter
  51. and Copper basically act as slaves to the main 680x0 processor.  The
  52. TAS instruction is used to support structure locking between peer CPUs
  53. which both share the same Amiga OS structures.  Any alternate
  54. processor that acts as a slave, such as the Amiga chips or perhaps a
  55. DMA device, will not share system structures and therefore, do not
  56. need the hardware bus locking provided by TAS.  Also, the design of
  57. the Chip bus makes it impossible to support any use of the 68000 TAS
  58. instruction to Chip memory anyway.  The custom chips get bus access
  59. for two out of every four system clock cycles, holding the 68000 off
  60. when they're on the bus.  The double TAS cycle conflicts with this
  61. mechanism, yielding unpredictable results.
  62.  
  63.  
  64.  
  65. A 68000 Bus Locking Primer
  66.  
  67. As mentioned, the problem with the use of TAS is primarily
  68. based on the way the 68000 implements its bus locking.  Unlike 68020
  69. and 68030 processors, which drive a special Read-Modify Cycle signal
  70. (RMC*) to indicate bus locking, the 68000 runs a modification of the
  71. normal 68000 bus cycle.
  72.  
  73.  
  74.  
  75. ******************* FIGURE 1 ******************
  76.  
  77.  
  78.  
  79. The normal 68000 bus cycle starts with the assertion of addresses and
  80. the read strobe (R/W), followed shortly by the assertion of address
  81. strobe (AS*) and the data strobes (UDS* and LDS*).  AS* is asserted
  82. during state S2, while the data strobes are asserted during state S2
  83. for read cycles, state S4 for write cycles.  The 68000 drives data for
  84. write cycles just before the data strobes, and samples data on read
  85. cycles on the falling edge of its clock at state S6.  In either case,
  86. it samples the data transfer acknowledge strobe (DTACK*) on the
  87. falling edge of state S4, and inserts wait states until DTACK* is
  88. asserted.  Once DTACK* is sampled, the cycle concludes with AS*, UDS*,
  89. LDS*, and most other signals being negated during S7 or shortly
  90. thereafter.  Figure 1 illustrates a standard 68000 read and write
  91. cycle.
  92.  
  93. The above read cycle followed by write cycle is quite sufficient for
  94. handling semaphores in a single processor system, if supported within
  95. a single instruction.  The 68000 family CPUs don't permit interrupts
  96. to be serviced except at instruction boundaries.  So the 68000 bit
  97. test instructions are adequate to support software semaphores in an
  98. interrupt driven multitasking single processor system.  Bus
  99. arbitration, on the other hand, is managed at cycle boundaries for the
  100. most part.  Ordinary I/O DMA devices such as hard disks don't
  101. interfere with this locking either, since such DMA devices don't
  102. access system structures.  All 680x0 locked cycles, including TAS,
  103. complete atomically even in the presence of a pending DMA request, so
  104. true bus locking isn't strictly necessary to handle semaphores between
  105. DMA processors using normal 680x0 bus arbitration to share memory.  A
  106. bus locking mechanism is, however, the proper way to handle resource
  107. locking of structures in a cycle-shared mailbox memory, such as the
  108. shared memory that's implemented on Amiga Bridgecards.
  109.  
  110.  
  111.  
  112. ******************* FIGURE 2 ******************
  113.  
  114.  
  115.  
  116. The 68000 TAS cycle works much like a normal read followed by a normal
  117. write, except that AS* is not negated between the read and write
  118. portions of the compound cycle.  Bus devices that expect AS* to
  119. qualify cycle boundaries, or devices that anticipate a minimum delay
  120. between the assertion of DTACK* and the negation of AS*, will fail
  121. with TAS cycles.  Both AS* and the data strobes must be used to
  122. identify the subcycle boundaries within the full TAS cycle.  The bus
  123. address doesn't change throughout the cycle, while the R/W line and
  124. data bus obey the timing of the individual subcycles.  DTACK* and
  125. other slave device signals will similarly respect the timing of the
  126. individual subcycles, as based on UDS* or LDS*.  Additionally, the TAS
  127. cycle contains extra clock cycles for the ALU operation, so that
  128. instead of the minimal eight clocks for a read cycle immediately
  129. followed by a write cycle, the minimum TAS cycle takes ten clocks.
  130. Figure 2 illustrates a 68000 TAS cycle.
  131.  
  132.  
  133.  
  134. Zorro II Bus Issues
  135.  
  136. The Zorro II expansion bus, being originally based on the 68000 CPU
  137. bus, by extension can run TAS cycles.  However, their use on the Zorro
  138. II bus is far from straightforward.  Although the original Zorro II
  139. specifications and the updated specifications published in the
  140. A500/A2000 Technical Reference Manual both require the M68000
  141. Users Manual as a companion specification, the use of TAS was never
  142. explicitly discussed for use on the bus.  Additionally, the use of TAS
  143. in Amiga Chip memory was explicitly forbidden, and at the time of the
  144. Zorro II specification writing, generally considered unsupported
  145. anywhere on Amiga computers.
  146.  
  147. Because of this ambiguity, many Zorro II devices don't support TAS
  148. cycles at all.  Therefore, the use of TAS is explicitly forbidden on
  149. any Zorro II device that isn't specifically known to support TAS.
  150. Even simple memory boards probably act unpredictably when driven with
  151. a TAS cycle.
  152.  
  153. Circuits that do support TAS must be very carefully designed
  154. to support it properly.  Due to clock skewing between the 68000 and
  155. the backplane, or alternate bus masters and the backplane, no Zorro II
  156. slave PIC that controls DTACK* via XRDY must assume it knows the delay
  157. between its negation of XRDY and the end of the cycle.  For any
  158. XRDY-controlled Zorro II cycle, the cycle's end is defined by the
  159. negation of AS* or UDS*/LDS*, which ever comes first.  This is a
  160. general rule (nothing specific to the TAS cycle), but one would expect
  161. the situations in which TAS is necessary, such as locking shared
  162. memory resources, to be more sensitive to any cycle delays.  All
  163. shared memory circuits must have some kind of memory arbiter, and such
  164. arbiters might be easier to design considering only outgoing signals
  165. such as XRDY.  However, designs that don't use AS* to end normal
  166. cycles and UDS*/LDS* to end the read half of the TAS cycle are very
  167. likely to cause trouble.  
  168.  
  169.  
  170.  
  171. ******************* FIGURE 3 ******************
  172.  
  173.  
  174.  
  175. Figure 3 illustrates how a reasonably designed XRDY based control
  176. circuit can possibly result in an unexpected wait state.  This example
  177. is assuming A2000 system timing.  Essentially, what this hypothetical
  178. device wants to do is terminate the current cycle by negating the XRDY
  179. line that it pulled properly at the start of the cycle.  The XRDY
  180. signal is being driven on the rising edge of the 7MHz clock, the
  181. result of a synchronous state machine that runs with 7MHz timing.
  182.  
  183. The A2000's Zorro II bus uses a buffered version of the 68000's
  184. 7MHz clock.  This can introduce clock delays of roughly 10ns between
  185. the actual 68000 clock and the bus clock.  The hypothetical circuit
  186. uses the rising edge of the clock to enable XRDY.  I'm assuming a
  187. total worst-case delay of 35ns here, which must take into account the
  188. PIC logic in the XRDY path: clock buffer, flip-flop and state machine
  189. logic, and an open collector output buffer to drive XRDY onto the bus.
  190. While XRDY circuits may be faster in some designs, this example is not
  191. unreasonable.  Once XRDY is asserted, there's the Gary chip delay to
  192. consider, which can be slower than 25ns in worst case.  Thus, in this
  193. example, DTACK* isn't asserted until over 70ns after the real 7MHz
  194. clock transition, even ignoring other small delays that can be
  195. incurred by bus loading or assymetry of the 7MHz clock.  In order to
  196. assure that DTACK* is sampled by the 68000 without an additional wait
  197. state, it must be asserted by the 68000 at least 10ns prior to the
  198. falling edge of the 7MHz clock.
  199.  
  200. Clearly, we're missing that in this example by at least 10ns, so the
  201. wait state is added.  Any logic on this hypothetical card that assumed
  202. the cycle would be over two clocks after XRDY was clocked will fail.
  203. Likewise, logic on that card that assumes the extra wait state will
  204. always be added would be just as fatal.  This example assumes worst
  205. case, but in a best case situation, the wait state would never happen.
  206.  
  207. Also, the characteristics of the Zorro II bus interface come into
  208. play.  An A2000 may take 25ns to recognize XRDY, but another backplane
  209. may treat it faster or slower.  The XRDY signal has always been
  210. treated as an asynchronous signal, and there is no guaranteed range of
  211. synchronous operation defined for this signal.  The AS* or UDS*/LDS*
  212. defined end of cycle must always be explicitly considered by a proper
  213. Zorro II XRDY controlled slave device (this is also a requirement
  214. defined by the 68000 specifications, though they don't explain the
  215. likely problems of not being strobe driven) [see footnote]***.
  216.  
  217. ***[footnote] I don't claim these problems should be immediately
  218. obvious to everyone.  Once mentioned, it should be pretty easy to
  219. recognize that pre-supposing the end of a bus cycle is dangerous.  I
  220. ran into this exact type of problem in the B revision of the A3000's
  221. Buster chip, so it can happen to anyone.  The current Buster, like any
  222. good design, is basing its end-of-cycle actions on the negation of the
  223. appropriate strobes, never the assumption on when DTACK* will take
  224. effect.
  225.  
  226. Any designs that must behave synchronously must assert OVR* to release
  227. the backplane's control of DTACK*, and then drive DTACK*
  228. synchronously.  The Zorro II requirements for synchronous operation
  229. with DTACK* controlled termination require that DTACK* be set up to
  230. the falling edge of S4 by 30ns, which is a sufficient amount of time
  231. to meet both the actual 68000 setup time and offset the effect of any
  232. clock skews on the backplane.  Alternate bus masters such as DMA
  233. driven hard disk controllers must of course take into account
  234. synchronous operation with DTACK* as one of the list of bus
  235. constraints they must meet.
  236.  
  237.  
  238.  
  239. TAS and the A2500
  240.  
  241. At the time the A2620 and A2630 were designed, the use of TAS on the
  242. expansion bus was still considered a dubious practice.  While TAS can,
  243. within the limits set forth in this document, be used successfully on
  244. some Amiga system, it is not completely supported in either A2500
  245. configuration.  As mentioned, the TAS cycle performs two major
  246. functions.  The first, which is supported by the A2500, is to provide
  247. an atomic cycle that will arbitrate a semaphore between DMA devices on
  248. the bus.  With A2500s, TAS is guaranteed to be atomic with respect to
  249. bus arbitration.  However, it does not generate 68000 compatible TAS
  250. cycles on the expansion bus.  The TAS instruction executed on either
  251. A2500 system will result in a standard 68000 read cycle followed by a
  252. standard 68000 write cycle.  Thus, there is no bus locking, so TAS
  253. won't be sufficient to arbitrate semaphores in shared mailbox type
  254. memory.  The best solution for such mailbox arbitration is to use
  255. software based spin lock semaphores or other methods which permit safe
  256. multiprocessing semaphores without the hardware bus locking.  If
  257. that's unacceptable for all Amigas, the TAS solution can be invoked on
  258. Amiga systems that support it, while the software-only solution can be
  259. invoked on A2500s or other 2500-class machines.  Software can
  260. determine the existence of a real A2500 by querying for an A2500 via
  261. the expansion library.  A2500s show up as Commodore products
  262. (manufacturer number $0202) numbers $50 (for A2500/20) or $51 (for
  263. A2500/30).
  264.  
  265. While you can explicitly check for operation on a true A2500, you
  266. cannot as easily determine in all cases if the machine is a similarly
  267. enhanced A2000 running with a third party accelerator board.  Without
  268. autoconfiguration units such as on real A2500s, software can only tell
  269. the CPU type.  Some third party coprocessor boards are available
  270. without memory or other permanent autoconfiguration units that
  271. software could use to identify the accelerator manufacturer.  Even
  272. some of those boards with memory don't autoconfigure it like they
  273. should.  Commodore does not have a list of which (if there are any)
  274. third party accelerator cards will fully support TAS cycles anyway.
  275. It is therefore important to assume that any 68020 or 68030 Amiga,
  276. except for the A3000, is not likely to support TAS and should instead
  277. handle bus locking in software.
  278.  
  279.  
  280.  
  281. TAS and the A3000
  282.  
  283. The A3000 does support 68000 compatible TAS cycles on its
  284. implementation of the Zorro II bus, but there are some caveats that
  285. must be considered.  Any differences from the A3000's implementation
  286. of the 68000-compatible TAS cycle stem from the fact that TAS is
  287. handled differently by the 68030.  The primary difference in 68030 TAS
  288. handling is that the 68030 runs two standard 68030 cycles in response
  289. to TAS, and locks the bus by way of the RMC* signal.  Also, while the
  290. 68000 specified the length of the ALU cycle between the read and write
  291. phases of the TAS instruction, the 68030 specifications do not
  292. quantify this part of the cycle.  When supporting the 68000 TAS cycle,
  293. the A3000's CPU is also running asynchronously to the Zorro II bus, so
  294. clock synchronization delays also creep in.
  295.  
  296. The result of all of this is that the length of the entire Zorro II
  297. TAS cycle on the Amiga 3000 bus can vary by one, and possibly two,
  298. 7MHz clock cycles.  The A3000 TAS cycle is shown in Figure 4.  The
  299. A3000 starts all bus cycles as Zorro III cycles, with the assertion of
  300. the Full Cycle Strobe (FCS*) shortly following the 68030's assertion
  301. of AS*.  When a Zorro II cycle is indicated, FCS* is sampled on the
  302. falling edge of CDAC, and then on the rising edge of the 7MHz clock.
  303. The diagram shows where FCS* and AS* might have been to give rise to
  304. the Zorro II cycle starting here.  The double-clocked FCS* will
  305. quickly create the A3000's 68000 compatible address strobe, CCS*, and
  306. in the case of a read cycle, the UDS*/LDS* equivalents called DS3* and
  307. DS2*, respectively.
  308.  
  309. The remainder of the read phase runs just as a 68000 cycle until
  310. DTACK* is sampled at the falling edge of S4.  DTACK* would normally
  311. cause CCS* and the data strobes to be negated at S6, but since this is
  312. a TAS cycle, only the data strobes are negated.  Also at this point,
  313. the expansion bus data is latched for the 68030 and the 68030's
  314. DSACK1* signal is asserted on the A3000's local bus.  This is the
  315. first cause of the cycle length ambiguity.  The 68030 is of course
  316. running asynchronous to the Zorro II cycle in progress, and so the
  317. time between the assertion of DSACK1* and the 68030's negation of AS*
  318. can be as quick as 40ns, for an A3000/25 that just manages to hit
  319. DSACK1* at the sample point.  It might also be as long as 120ns for an
  320. A3000/16 that just misses the sample point.  If the worst-case timing
  321. of the 68030 is considered, this last delay could actually be as long
  322. as 150ns.  Once AS* is negated, DSACK1* will be negated and the 68030
  323. cycle ends, though the Zorro II within Zorro III cycle-in-progress
  324. remains active.
  325.  
  326.  
  327.  
  328. ******************* FIGURE 4 ******************
  329.  
  330.  
  331.  
  332. The next half of the TAS cycle starts with the 68030's assertion of
  333. AS* again.  There is more cycle length ambiguity introduced here,
  334. since the 68030 specification does not document the number of clocks a
  335. TAS ALU cycle will take.  Since any 68030 clock cycle is only a
  336. fraction of a Zorro II cycle, this isn't expected to be a drastic
  337. ambiguity, but it's something to consider.  Since the FCS* strobe is
  338. already asserted, the A3000 bus controller effectively samples AS*,
  339. first with the falling CDAC clock and then with the rising 7MHz clock,
  340. to start the write section of the TAS cycle.  Based on the intercycle
  341. ambiguities as seen from the 68030's perspective, this second bus
  342. cycle will sometimes start early, other times late.  Figure 4 shows
  343. the likely best and worst case secondary cycles, which ultimately
  344. depend on whether or not AS* is asserted quickly enough to be clocked
  345. by the falling CDAC in S11, or whether it must wait until S13.
  346.  
  347. However that gets settled, the bus controller drives DS3*/DS2*,
  348. samples DTACK*, and ultimately negates both data strobes and CCS*.
  349. Following this end of the Zorro II cycle, the DSACK1* strobe is
  350. asserted onto the local bus, the 68030 sees this within 40ns or 60ns
  351. of it being asserted, and AS* followed by DSACK* are negated, ending
  352. the local bus cycle.  FCS* is quickly negated based on AS*, and the
  353. cycle ends.
  354.  
  355.  
  356.  
  357. The Final Word
  358.  
  359. So that's a fairly complete description of the behavior of TAS on all
  360. currently known implementations of the Zorro II bus.  While things
  361. like XRDY to cycle's end and the total length of the TAS cycle aren't
  362. always the same between the different backplanes, this doesn't matter
  363. for correctly designed expansion cards.
  364.  
  365. Use XRDY for asynchronous operation, OVR*, DTACK*, and C7M for
  366. synchronous or asynchronous operation.  Any cards that find this does
  367. matter should avoid using TAS, since they will get into trouble sooner
  368. or later.  The main concern to devices that want to support TAS will
  369. be the incomplete operation of TAS in A2500 and 2500 look-a-like
  370. systems.  These devices must provide some software lock mechanism when
  371. on an A2500, which can be replaced with hardware locking on 68000
  372. based Amigas and A3000s, if necessary.
  373.  
  374. An A3000 specific design can be a Zorro III card and use the /LOCK
  375. signal and the TAS, CAS, or CAS2 instructions for bus locking,
  376. bypassing all the 68000-inspired nonsense completely.
  377.